home *** CD-ROM | disk | FTP | other *** search
/ PC-Blue - MS DOS Public Domain Library / PC-Blue MS-DOS Public Domain Library - NYACC.iso / vol061 / sheldemo.bas < prev    next >
Encoding:
BASIC Source File  |  1987-01-13  |  4.5 KB  |  79 lines

  1. 10 ' SHELDEMO.BAS
  2. 20 '
  3. 30 ' March 14, 1984
  4. 40 '
  5. 50 ' Written by Wes Meier (70215,1017)
  6. 60 '
  7. 70 ' RBBS - (415)-937-0156 ...... the Walnut Creek RBBS.
  8. 80 '
  9. 90 ' ───────────────────────────────────────────────────────────────────────
  10. 100 ' A Demonstration of the undocumented BASIC 2.00 SHELL command.
  11. 110 '───────────────────────────────────────────────────────────────────────
  12. 120 ' Syntax:   SHELL "dos command"   OR   SHELL stringvar (where stringvar
  13. 130 ' has been set equal to a valid DOS command).
  14. 140 '───────────────────────────────────────────────────────────────────────
  15. 150 ' Comments:
  16. 160 '
  17. 170 '    1) The SHELL command works in that it WILL execute any valid DOS
  18. 180 '       command from BASIC. The problem is that the pointers used by
  19. 190 '       BASIC to indicate the start of program text are clobbered by the
  20. 200 '       SHELL routine's execution. Hence, upon return from the execution
  21. 210 '       of a command, poor old BASIC doesn't have the slightest idea where
  22. 220 '       to restart execution of a program which has ended or has been
  23. 230 '       redirected by a gosub, goto, etc.
  24. 240 '
  25. 250 '       Fortunately, SHELL does NOT clobber variables. So, if we look up
  26. 260 '       the value of the "start of program text" pointers and assign their
  27. 270 '       values to variables, we can POKE the values back into the
  28. 280 '       locations that BASIC expects to see them. This two byte pointer is
  29. 290 '       located at relative bytes 30H and 31H in BASIC's segment. See the
  30. 300 '       Technical Reference Manual, page 3-23.
  31. 310 '
  32. 320 '    2) It apprears that SHELL moves both BASIC and program text up into
  33. 330 '       high memory and then moves it back down again after execution. This
  34. 340 '       can cause problems if the DOS command executes a large program and
  35. 350 '       overwrites THIS area of memory. EG, SHELL "1-2-3" would most likely
  36. 360 '       blow your resident BASIC driver program away. Stick with the
  37. 370 '       utility commands like CHKDSK, DIR, MODE, etc. Most .COM programs
  38. 380 '       load into low memory while MANY (but not all) .EXE programs load
  39. 390 '       into high memory which would generally cause you to take a trip
  40. 400 '       to where Peter Pan lives.
  41. 410 '
  42. 420 '    3) The current cursor location (in BASIC) is NOT updated to account
  43. 430 '       for any screen I/O generated by the DOS command executed.
  44. 440 '
  45. 450 '    4) SHELL was left undocumented for good reason. It probably has
  46. 460 '       bugs that were not ironed out by our friends at Microsoft by the
  47. 470 '       time Big Blue wanted to release BASIC 2.00. USE IT WITH CAUTION!
  48. 480 '
  49. 490 '       One "bug" (feature?) I've found is that it's easy to confuse
  50. 500 '       SHELL and/or DOS (running via SHELL) into staying at the DOS
  51. 510 '       prompt. If you try to get back to BASIC(A), you'll get a charming
  52. 520 '       error message that states "You cannot run Basic as a Child of
  53. 530 '       Basic." I suspect that this prevents recursive loops.
  54. 540 '───────────────────────────────────────────────────────────────────────
  55. 550 ' The following short program demonstrates a relatively successful way
  56. 560 ' to use the SHELL command.           --- Good Luck! ---
  57. 570 '                                                            - Wes
  58. 580 '───────────────────────────────────────────────────────────────────────
  59. 590 CLS
  60. 600 DEF SEG             ' Set the segment register to BASIC's default.
  61. 610 '
  62. 620 LSB=PEEK(&H30)      ' Get the Least Significant Byte of the pointer.
  63. 630 MSB=PEEK(&H31)      ' Get the Most Significant Byte of the pointer.
  64. 640 '
  65. 650 PRINT
  66. 660 LINE INPUT"Enter DOS Command to  be executed ";DOS.COMMAND$
  67. 670 '
  68. 680 SHELL DOS.COMMAND$  ' Execute the command entered.
  69. 690 '
  70. 700 ' At this point, BASIC's pointers at 30H and 31H have been ZAPPED.
  71. 710 ' We need to reload them.....
  72. 720 '
  73. 730 POKE &H30,LSB       ' Reload the LSB of the pointer.
  74. 740 POKE &H31,MSB       ' Reload the MSB of the pointer.
  75. 750 '
  76. 760 GOTO 650            ' Go back for another run.
  77. 770 '
  78. 780 '                     Last line of SHELDEMO.BAS.
  79.